package cn.edu.scut.hsrc.cluster;

import cn.edu.scut.hsrc.bean.Doc;
import cn.edu.scut.hsrc.cluster.semantic.Cluster;
import cn.edu.scut.hsrc.cluster.semantic.PreProcessor;
import cn.edu.scut.hsrc.cluster.semantic.Relation;
import cn.edu.scut.hsrc.output.ClusterResult;

/**
 * 包装类，对整个聚类过程进行包装，给外部提供一个统一的接口进行访问
 * @file HSRC.java
 * @author feiyu
 *
 */

public class SemanticCluster extends ICluster{
	
	private final String query;
	private final Doc [] docs;
	
	public SemanticCluster(String query,Doc [] docs) {
		// TODO Auto-generated constructor stub
		this.query = query;
		this.docs = docs;
	}

	/**
	 * 语义聚类
	 */
	@Override
	public ClusterResult[] doCluster()
	{
		Doc [] docs = this.docs;
		//预处理
		PreProcessor preProcessor = new PreProcessor(this.query, docs);
		preProcessor.doPreProcess();
		docs = preProcessor.getDocs();
		//分析关联关系
		Relation relation = new Relation(this.query, docs, preProcessor.getSegedQuery());
		relation.doRelation();
		//聚类
		Cluster cluster = new Cluster(docs,  relation.getSeqDocs(), relation.getDocWords(), relation.getAllWords(),relation.getCandidateWords(),relation.getDocSimMatrix());
		return cluster.doCluster();
	}
}

